// 路由配置
import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/login.vue';
import store from "../store";

Vue.use(VueRouter);

// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [{
  path: '/',
  redirect: '/login',
}, {
  path: '/login',
  name: 'login',
  component: Login,
}, {
  path: '/home', //整体页面布局
  name: 'home',
  meta:{ title: '首页' },
  component: () => import(/* webpackChunkName: "home" */ '@/views/HomeView.vue'),
  redirect: '/home/systemManage',
  children: [
    {
      path: 'systemManage', //子路由path不加
      name: 'SystemManage',
      meta:{ title: '系统管理' },
      component: () => import(/* webpackChunkName: "home" */ '@/components/Layout/Main.vue'),
      redirect: '/home/systemManage/user',
      children: [{
        path: 'user',
        name: 'User',
        meta:{ title: '用户管理'},
        component: () => import(/* webpackChunkName: "home" */ '@/views/systemManage/User.vue')
      }, {
        path: 'role',
        name: 'Role',
        meta:{ title: '角色管理' },
        component: () => import(/* webpackChunkName: "home" */ '@/views/systemManage/Role.vue')
      }, {
        path: 'menu',
        name: 'Menu',
        meta:{title:'菜单管理'},
        component: () => import(/* webpackChunkName: "home" */ '@/components/Layout/Main.vue'),
        redirect: '/home/systemManage/menu/routeMenu',
        children:[{
          path:'routeMenu',
          name:'RouteMenu',
          meta:{title:'路由菜单'},
          component: () => import(/* webpackChunkName: "home" */ '@/views/systemManage/Menu.vue'),
        }]
      }]
    }, {
      path: 'settingManage',
      name: 'SettingManage',
      meta:{title: '设置管理'},
      component: () => import(/* webpackChunkName: "home" */ '@/views/settingManage/Setting.vue')
    }, {
      path: 'tableManage',
      name: 'TableManage',
      meta:{title: '表格管理' },
      component: () => import(/* webpackChunkName: "home" */ '@/components/Layout/Main.vue'),
      children: [
        {
          path: 'basicTable',
          name: 'BasicTable',
          meta:{ title: '基础表格'},
          component: () => import(/* webpackChunkName: "home" */ '@/views/tableManage/BasicTable.vue')
        }, {
          path: 'advancedTable',
          name: 'AdvancedTable',
          meta:{title: '进阶表格'},
          component: () => import(/* webpackChunkName: "home" */ '@/views/tableManage/AdvancedTable.vue')
        },{
          path:'merageTable',
          name:'MerageTable',
          mata:{title:'合并表格'},
          component:()=>import(/* webpackChunkName: "home" */ '@/views/tableManage/MerageTable.vue')
        }
      ]
    }, {
      path: 'formManage',
      name: 'FormManage',
      meta:{title: '菜单管理'},
      component: () => import(/* webpackChunkName: "home" */ '@/views/formManage/form.vue')
    },{
      path:'personal',
      name:'Personal',
      meta:{title:'用户管理'},
      component: () => import(/* webpackChunkName: "home" */ '@/components/Layout/Main.vue'),
      children:[
        {
          path: 'userInfo',
          name: 'UserInfo',
          meta:{title: '个人信息'},
          component: () => import(/* webpackChunkName: "home" */ '@/views/user/info.vue')
        }
      ]
    }
  ]
}
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.VUE_APP_BASE_URL,
  routes
})


export default router
